@tool
@icon("../icons/animation_player_state.svg")
class_name State_AnimationPlayer
extends State_Atomic

#region 属性
@export var animation_name:StringName = ""
@export var custom_blend:float = -1.0
@export var custom_speed:float = 1.0
@export var from_end:bool = false
var _animation_player:AnimationPlayer
#endregion
#region 字段
@export_node_path("AnimationPlayer") var animation_player:NodePath:
	set(value):
		animation_player = value
		update_configuration_warnings()
#endregion
#region 信号
#endregion

#region 基类方法
func enter(expect_transition:bool = false):
	super()
	if not is_instance_valid(_animation_player):
		return
	var target_animation = animation_name
	if target_animation == "":
		target_animation = get_name()
	if _animation_player.current_animation == target_animation and _animation_player.is_playing():
		return
	_animation_player.play(target_animation,custom_blend,custom_speed,from_end)
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _ready() -> void:
	if Engine.is_editor_hint():
		return
	super()
	_animation_player = get_node_or_null(animation_player)
	if not is_instance_valid(_animation_player):
		push_error("animation_player 无效")
func _get_configuration_warnings():
	var warnings = super._get_configuration_warnings()
	if animation_player.is_empty():
		warnings.append("未设置animation_player")
	elif get_node_or_null(animation_player) == null:
		warnings.append("animation_player 无效")
	return warnings
#endregion
